<?php
    namespace Admin\Model;

    use Common\Model\CommonModel;

    class CardReplaceModel extends CommonModel {

        /**
         * 卡片更换记录
         */
        public function get_list($where = array(),$from,$to){
            $list = M("CardReplace")->field("*")->where($where)
                ->order("create_time")
                ->limit($from ,$to)
                ->select();
            return $list;
        }

        /**
         * 获取单个信息
         */
        public function get_one($where){
            $item = M("CardReplace")->field("*")->where($where)
                ->find();
            return $item;
        }

        /**
         * 更新
         */
        public function update_data($data,$id){
            $data = array_merge($data,['update_time'=>time()]);
            $result = M("CardReplace")->where(['id'=>$id])->save($data);
            return $result;
        }

        /**
         * 新增
         */
        public function add_data($insert){
            $insert = array_merge($insert,['create_time'=>time()]);
            $result =  M("CardReplace")->add($insert);
            return $result;
        }

        /**
         * 换卡
         */
        public function active_card($old_card_number,$new_card_number){
            $card = D("Admin/Card")->get_one(['number'=>$old_card_number]);
            if($card){

            }
        }
    }